﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Twodi.Structs;
using Twodi.Utility;

namespace Twodi.Implemented
{
    public class DrawableLine : Sprite
    {

        protected int thickness = 1;

        protected Line line;

        public DrawableLine(Game game)
            : base(Helper.CreateSquareTexture(game, 1, 1, Color.White), game)
        {

        }

        public override void Render(GameTime gameTime)
        {
            if (ValidSpriteBatch)
            {
                SpriteBatch.Draw(Texture, Begin, null, Color.White, (float)line.Angle, Vector2.Zero, new Vector2(Distance, Thickness), SpriteEffects.None, 0);
            }
        }

        public int Thickness
        {
            get { return this.thickness; }
            set
            {
                this.thickness = value;
                onThicknessChanged(EventArgs.Empty);
            }
        }

        public Vector2 Begin
        {
            get
            {
                return line.Begin;
            }
            set
            {
                line.Begin = value;
            }
        }

        public Vector2 End
        {
            get
            {
                return line.End;
            }
            set
            {
                line.End = value;
            }
        }

        public float Distance
        {
            get
            {
                return line.Distance;
            }
        }

        public event EventHandler<EventArgs> ThicknessChanged;

        protected virtual void onThicknessChanged(EventArgs e)
        {
            if (ThicknessChanged != null)
            {
                ThicknessChanged(this, e);
            }
        }
    }
}
